package server;

public class pingChecker extends Thread{
    clientConnection clientPinged = null;
    public int pingCnt = 3;
	
	public pingChecker(clientConnection c){
		this.clientPinged = c;
	}
    
    public synchronized void run(){	
    	try {
			Thread.sleep(2000);
		}
		catch (InterruptedException e) {
			e.printStackTrace();
		}
    	
    	while(pingCnt > 0){
    		try {
				Thread.sleep(1000);
			}
    		catch (InterruptedException e) {
				e.printStackTrace();
			}
			System.out.println("Ping received.");
			this.pingCnt--;
    	}
    	
    	if(clientPinged.matched){
    		System.err.println("Exiting pingChecker.");
    		return;
    	}
    	else if(!clientPinged.pingerFailFlag){
    		clientPinged.pingerFailFlag = true;
    		System.err.println("Exiting pingChecker after user removal.");
			return;
		}
    	return;
    	}
		
}
